package com.huchao.www.controller;

import com.huchao.www.exception.MyException;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;


/**
 * @Description:
 * @BelongsProject: springMVC
 * @BelongsPackage: com.huchao.www.controller
 * @Author: 亖思
 * @CreateTime: 2022/12/7 20:13
 * @Version: 1.0
 */


@ControllerAdvice
public class ExceptionAdvice {

    /**
     * 〈登录验证异常处理〉
     * @param e:参数校验异常
     * @param model:
     * @Author: 亖思
     * @Date: 2022/12/8 13:00
     * @return: String
     **/
    @ExceptionHandler(MyException.class)
    public ModelAndView loginException(MyException e, Model model, HttpServletRequest request){
       ModelAndView mv = new ModelAndView();
       mv.addObject("timeout",e.getTimeout());
       mv.addObject("url",e.getUrl());
       mv.addObject("message",e.getMessage());
       mv.setViewName("error/show_msg");
       return mv;
    }
}
